package util;

import java.text.DecimalFormat;
import java.util.regex.Pattern;

/**
 * 输出工具
 */

public final class PrintUtil {
    private PrintUtil() {}

    public static final int SCREEN_LENGTH = 100;

    /**
     * 普通的输出短字符串
     */
    public static void printString(String description) {
        System.out.println(description);
    }

    /**
     * 打印长内容字符串，避免超出屏幕
     * @param str 长字符串
     */
    public static void printLongString(String str) {
        StringBuffer buffer=new StringBuffer();
        int new_line=0;
        for (int i = 0; i <str.length(); i++) {
            buffer.append(str.charAt(i));
            if(Pattern.matches("[\u4e00-\u9fa5]",""+str.charAt(i)))
                new_line+=2;
            else
                new_line++;
            if(new_line>=SCREEN_LENGTH){
                buffer.append("\n");
                new_line=0;
            }
        }
        System.out.println(buffer);
    }

    /**
     * 打印操作选项
     * @param funcNum  选项数字
     * @param funcDescription 选项描述
     */
    public static void printFunc(int funcNum, String funcDescription) {
        System.out.println(funcNum + ". " + funcDescription);
    }

    /**
     * 根据屏幕宽度打印线条 -
     */
    public static void printLine() {
        int count = PrintUtil.SCREEN_LENGTH;
        while (count-- > 1) {
            System.out.print("-");
        }
        System.out.println();
    }

}
